import os
import imageio.v2 as imageio
from PIL import Image

# 拆分 gif
# im = Image.open('images/跳舞.gif')
# try:
#     i = 1
#     while True:
#         # 通过异常退出循环
#         im.seek(i)
#         im.save('images/frames/'+str(i)+'.png')
#         i = i +1
# except:
#     pass
# print('共拆解图像帧数'+str(i))


# 合并 gif
images = []
numberlist = os.listdir('images/charGrayFrames')
for i in range(len(numberlist)):
    images.append(imageio.imread('images/charGrayFrames/'+numberlist[i]))
# imageio.help('GIF-FI')
imageio.mimsave("grayChar.gif", images, duration=0.1, loop=0)   # 转化为gif动画